package org.feng.utils.redis;

import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author by feng
 * @des redisSet
 * @date 2021/4/27 14:03
 */
@Component
public class RedisSet extends RedisCommon {
    /**
     * 获取集合中所有值
     *
     * @param key
     * @return
     */
    public Set<Object> get(Object key) {
        return redisTemplate.opsForSet().members(key);
    }

    /**
     * 新增元素
     *
     * @param key
     * @param vs
     */
    public void add(Object key, Object... vs) {
        redisTemplate.opsForSet().add(key, vs);
    }

    /**
     * 删除元素
     *
     * @param key
     * @param vs
     */
    public void delete(Object key, Object... vs) {
        redisTemplate.opsForSet().remove(key, vs);

    }

    /**
     * 判断是否存在
     *
     * @param key
     * @param vs
     * @return
     */
//    public Boolean exits(Object key, Object... vs) {
//        return redisTemplate.opsForSet().isMember(key, vs);
//
//    }

    /**
     * 多个集合得并集
     *
     * @param key1
     * @param key2
     * @return
     */
    public Set<Object> union(Object key1, Object key2) {
        return redisTemplate.opsForSet().union(key1, key2);
    }

    /**
     * 多个集合得交集
     *
     * @param key1
     * @param key2
     * @return
     */
    public Set<Object> intersect(Object key1, Object key2) {
        return redisTemplate.opsForSet().intersect(key1, key2);
    }

    /**
     * 返回集合key1中存在，但是key2中不存在的数据集合
     *
     * @param key1
     * @param key2
     * @return
     */
    public Set<Object> diff(Object key1, Object key2) {
        return redisTemplate.opsForSet().difference(key1, key2);
    }
}
